package cn.larry.common.blockchain;

/**
 * This is created,
 * but not necessarily updated by me.
 * Therefore, AUTHOR is useless.
 * 2024/10/11 11:35
 *
 * @Version 1.0
 */
public class BlockchainTest {
    public static void main(String[] args) {
//        Blockchain.addBlock(new Block("First block", "0"));
//        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
//        Blockchain.addBlock(new Block("Third block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
//
//        System.out.println("Blockchain is valid: " + Blockchain.isChainValid());
//        System.out.println(StringUtil.getJson(Blockchain.blockchain));

//        Block(hash=0000046f678d09c489a4539bcf92479898c2301b267735671c1cf9803b93ca1c, previousHash=0, data=First block, timeStamp=1729156810961, nonce=2043237),

        String s = StringUtil.applySha256("0" + Long.toString(1729156810961L) + Integer.toString(2043237) + "First block");
        System.out.println(s.equals("0000046f678d09c489a4539bcf92479898c2301b267735671c1cf9803b93ca1c"));


        Blockchain.addBlock(new Block("First block", "0"));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));
        Blockchain.addBlock(new Block("Second block", Blockchain.blockchain.get(Blockchain.blockchain.size() - 1).hash));


        System.out.println("Blockchain is valid: " + Blockchain.isChainValid());
        System.out.println("Blockchain is valid: " + Blockchain.blockchain.remove(2));
        System.out.println("Blockchain is valid: " + Blockchain.isChainValid());
        System.out.println(StringUtil.getJson(Blockchain.blockchain));

//        Block Mined!!! : 0000058956edca2ba13ca7f57fb9431cf694daa0944355f6dfb0e09a9cffb7df
//        0000058956edca2ba13ca7f57fb9431cf694daa0944355f6dfb0e09a9cffb7df
//        0000058956edca2ba13ca7f57fb9431cf694daa0944355f6dfb0e09a9cffb7df
//        0000058956edca2ba13ca7f57fb9431cf694daa0944355f6dfb0e09a9cffb7df
//        0000058956edca2ba13ca7f57fb9431cf694daa0944355f6dfb0e09a9cffb7df
//        0000058956edca2ba13ca7f57fb9431cf694daa0944355f6dfb0e09a9cffb7df
//        0000058956edca2ba13ca7f57fb9431cf694daa0944355f6dfb0e09a9cffb7df


    }

}
